package leetcode;

import java.util.HashSet;

public class Solution {

  public static void main(String[] args) {

    InheritableThreadLocal main = new InheritableThreadLocal();



    // threadLocalDemo1();
    //inheritablethreadlocalDemo1();
    // hashSetDemo1();
  }

  public static void hashSetDemo1() {
    HashSet set = new HashSet();
    InheritableThreadLocal tl = new InheritableThreadLocal();
    set.add(1);
    System.out.println(
        String.format("当前线程名称: %s, main方法内获取线程内数据为: %s", Thread.currentThread().getName(), set));

    new Thread(
            () -> {
              System.out.println(
                  String.format(
                      "当前线程名称: %s, fc方法内获取线程内数据为: %s", Thread.currentThread().getName(), set));
            })
        .start();
    new Thread().start();
  }

  public static void inheritablethreadlocalDemo1() {
    InheritableThreadLocal tl = new InheritableThreadLocal();
    tl.set(1);
    System.out.println(
        String.format(
            "当前线程名称: %s, main方法内获取线程内数据为: %s", Thread.currentThread().getName(), tl.get()));

    new Thread(
            () -> {
              System.out.println(
                  String.format(
                      "当前线程名称: %s, fc方法内获取线程内数据为: %s", Thread.currentThread().getName(), tl.get()));
            })
        .start();
    new Thread().start();
  }

  public static void threadLocalDemo1() {
    ThreadLocal tl = new ThreadLocal<>();
    tl.set(1);
    System.out.println(
        String.format(
            "当前线程名称: %s, main方法内获取线程内数据为: %s", Thread.currentThread().getName(), tl.get()));
    new Thread(
            () -> {
              System.out.println(
                  String.format(
                      "当前线程名称: %s, fc方法内获取线程内数据为: %s", Thread.currentThread().getName(), tl.get()));
            })
        .start();
    new Thread().start();
  }
}
